﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Padsurface.App.Views.StartPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Padsurface.App.Views"
    xmlns:common="using:Padsurface.App.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:views="using:Padsurface.App.Views"
    xmlns:designdata="using:Padsurface.App.ViewModels.Start"
    mc:Ignorable="d"
    d:DataContext="{Binding Source={d:DesignInstance Type=designdata:DesignTimeData, IsDesignTimeCreatable=True}}">
    
    <Page.Resources>
        <CollectionViewSource x:Name="recentProjectsViewSource" 
                              Source="{Binding RecentSongs}"
                              d:Source="{Binding RecentSongs, Source={d:DesignInstance Type=designdata:DesignTimeData, IsDesignTimeCreatable=True}}"/>

        <Style x:Key="PageSubheaderButtonStyle" TargetType="Button">
            <Setter Property="Foreground" Value="{StaticResource ApplicationForegroundThemeBrush}"/>
            <Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}"/>
            <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/>
            <Setter Property="Typography.StylisticSet20" Value="True"/>
            <Setter Property="Typography.DiscretionaryLigatures" Value="True"/>
            <Setter Property="Typography.CaseSensitiveForms" Value="True"/>
            <!-- Properly align text along its baseline -->
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform X="-1" Y="4"/>
                </Setter.Value>
            </Setter>
            <Setter Property="FontSize" Value="26.667"/>
            <Setter Property="FontWeight" Value="Light"/>
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform X="-1" Y="6"/>
                </Setter.Value>
            </Setter>
            <Setter Property="VerticalAlignment" Value="Bottom"/>
            <Setter Property="Margin" Value="0,0,0,0"/>
            <Setter Property="BorderThickness" Value="0"/>
        </Style>

        <Style x:Key="PageSubheaderSubTextStyle" TargetType="TextBlock" BasedOn="{StaticResource BasicTextStyle}">
            <Setter Property="Foreground" Value="{StaticResource ApplicationSecondaryForegroundThemeBrush}" />
            <Setter Property="Margin" Value="0,0,0,16" />
        </Style>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>
        
        <Grid x:Name="fullScreenStartGrid" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            
            <StackPanel Grid.Column="0" Margin="120,0,0,0">
                <TextBlock x:Uid="RecentProjects" Text="Recent*" Style="{StaticResource PageSubheaderTextStyle}" Foreground="{StaticResource ApplicationSecondaryForegroundThemeBrush}"
                           Margin="0,16,0,40"/>

                <ListView ItemsSource="{Binding Source={StaticResource recentProjectsViewSource}}" Margin="0,0,0,60"
                          SelectionMode="Single">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Button Content="{Binding Name}" Command="{Binding LoadSongCommand}" CommandParameter="{Binding}" BorderThickness="0" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackPanel>

            <Border Grid.Column="1" BorderThickness="1,0,0,0" BorderBrush="{StaticResource ApplicationSecondaryForegroundThemeBrush}">
                <StackPanel>
                    <Button Command="{Binding CreateSongCommand}" Style="{StaticResource PageSubheaderButtonStyle}">
                        <StackPanel>
                            <TextBlock x:Uid="NewProject" Text="New*" Style="{StaticResource PageSubheaderTextStyle}" Margin="0,0,0,20" Width="200" />
                            <TextBlock x:Uid="NewProjectHelp" Text="Start a new song*" Style="{StaticResource PageSubheaderSubTextStyle}" />
                        </StackPanel>
                    </Button>

                    <Button Command="{Binding BrowseSongCommand}" Style="{StaticResource PageSubheaderButtonStyle}">
                        <StackPanel>
                            <TextBlock x:Uid="OpenProject" Text="Open*" Style="{StaticResource PageSubheaderTextStyle}" Margin="0,0,0,20" Width="200" />
                            <TextBlock x:Uid="OpenProjectHelp" Text="Continue an existing song*" Style="{StaticResource PageSubheaderSubTextStyle}" />
                        </StackPanel>
                    </Button>
                </StackPanel>
            </Border>
        </Grid>
        
        <Grid x:Name="snappedStartGrid" Grid.Row="1" Visibility="Collapsed">
            <StackPanel Orientation="Vertical">
                <Button Content="New" Style="{StaticResource PageSubheaderButtonStyle}" Margin="20,0,0,0"></Button>
                <Button Content="Open" Style="{StaticResource PageSubheaderButtonStyle}" Margin="20,0,0,0"></Button>
                <TextBlock Text="Recent" Style="{StaticResource PageSubheaderTextStyle}" Foreground="{StaticResource ApplicationSecondaryForegroundThemeBrush}" Margin="36,14,0,0" />
                <ListView ItemsSource="{Binding Source={StaticResource recentProjectsViewSource}}" Margin="0,0,0,60">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackPanel>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="fullScreenStartGrid" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="snappedStartGrid" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="fullScreenStartGrid" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="snappedStartGrid" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
